package com.ganbo.thread.wait;

/**
 * @Author: ganbo
 * @Date: 2020/5/20 15:59
 */
public class Service extends Thread {

    private Object lock;

    @Override
    public void run() {
        testMethod(lock);
    }

    public void testMethod(Object lock) {
        try {
            synchronized (lock) {
                System.out.println("1111isInterrupted===>" + Thread.currentThread().isInterrupted());
                System.out.println("begin wait();");
                lock.wait();
                System.out.println("end wait();");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();

            System.out.println("isInterrupted===>" + Thread.currentThread().isInterrupted());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Service service = new Service();
        service.lock = service;

        service.start();

        Thread.sleep(5000);

        service.interrupt();

        Thread.sleep(1000);

        service.interrupt();
        System.out.println("main()====>" + service.isInterrupted());

    }
}
